package org.soarsky.wealthchengdu.google.map;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Projection;

import android.graphics.Point;



public class PointContorlGoogle extends PointContorl{
	private MapView mapView = null;
	private Point pointScreen = null;
	private Point pointPrev = null;
	private Point pointNext = null;
	private Projection projection = null;
	private GeoPoint geoPointOverlap = null;
	public PointContorlGoogle(MapView mapView) {
		this.mapView = mapView;
		projection = mapView.getProjection();
		pointScreen = new Point();
		pointPrev = new Point();
		pointNext = new Point();
	}
	public PointContorlGoogle(){
		
	}
	public boolean isInTheScreen(GeoPoint geoPoint) {
		if(null==mapView)return false;
		screenSizeChange(mapView.getWidth(), mapView.getHeight());
		projection.toPixels(geoPoint, pointScreen);
		return isInTheScreen(pointScreen);
	}
	
	public boolean isOverlap(GeoPoint geoPoint) {
		if(null!=geoPointOverlap){
			if(null==pointPrev||pointNext==null)return false;
			projection.toPixels(geoPointOverlap, pointPrev);
			projection.toPixels(geoPoint, pointNext);
			return isOverlap(pointPrev, pointNext);
		}else {
			geoPointOverlap = geoPoint;
		}
		return false;
	}
	public GeoPoint createGeoPoint(double latitude,double longitude){
		return new GeoPoint((int) (latitude * 1E6), (int) (longitude * 1E6));
	}
	public void clear() {
		geoPointOverlap = null;
	}
	public void distory(){
		clear();
		pointScreen = null;
		pointPrev = null;
		pointNext = null;
	}
}
